import tensorflow.contrib.slim as slim
#[TensorFlow中的图片分类模型库slim的使用、数据集处理](https://www.cnblogs.com/zyly/p/9145081.html)
"""
slim的子模块及功能介绍：

    arg_scope: provides a new scope named arg_scope that allows a user to define default arguments for specific operations within that scope.

除了基本的namescope，variabelscope外，又加了argscope，它是用来控制每一层的默认超参数的。（后面会详细说）

data: contains TF-slim's dataset definition, data providers, parallel_reader, and decoding utilities.
貌似slim里面还有一套自己的数据定义，这个跳过，我们用的不多。
evaluation: contains routines for evaluating models.
    评估模型的一些方法，用的也不多
layers: contains high level layers for building models using tensorflow.
    这个比较重要，slim的核心和精髓，一些复杂层的定义
learning: contains routines for training models.
    一些训练规则

losses: contains commonly used loss functions.
    一些loss
metrics: contains popular evaluation metrics.
    评估模型的度量标准
nets: contains popular network definitions such as VGG and AlexNet models.
    包含一些经典网络，VGG等，用的也比较多
queues: provides a context manager for easily and safely starting and closing QueueRunners.
    文本队列管理，比较有用。

regularizers: contains weight regularizers.
    包含一些正则规则
variables: provides convenience wrappers for variable creation and manipulation.
"""
# Model Variables
weights = slim.model_variable('weights',
                              shape=[10, 10, 3, 3],
                              initializer=tf.truncated_normal_initializer(stddev=0.1),
                              regularizer=slim.l2_regularizer(0.05),
                              device='/CPU:0')
model_variables = slim.get_model_variables()
# Regular variables
my_var = slim.variable('my_var',
                       shape=[20, 1],
                       initializer=tf.zeros_initializer())
regular_variables_and_model_variables = slim.get_variables()
# 在第一个arg_scope中，卷积层和全连接层被应用于相同的权重初始化和权重正则化；
# 在第二个arg_scope中，额外的参数仅仅对卷积层conv2d起作用。
with slim.arg_scope([slim.conv2d, slim.fully_connected],
                    activation_fn=tf.nn.relu,
                    weights_initializer=tf.truncated_normal_initializer(stddev=0.01),
                    weights_regularizer=slim.l2_regularizer(0.0005)):
    with slim.arg_scope([slim.conv2d], stride=1, padding='SAME'):
        net = slim.conv2d(inputs, 64, [11, 11], 4, padding='VALID', scope='conv1')
        net = slim.conv2d(net, 256, [5, 5],
                          weights_initializer=tf.truncated_normal_initializer(stddev=0.03),
                          scope='conv2')
        net = slim.fully_connected(net, 1000, activation_fn=None, scope='fc')
